#include "findMisMatch_cpu.h"

bool compareBase(char a, char b)
{
	a = toupper(a);
	b = toupper(b);
	return a == b;
}

void findMisMatch(char* read, char* ref, unsigned int* queryId, unsigned int *pos,unsigned int *offset,  struct Info  *mis)
{
	unsigned int readPos, refPos, readLength, numSA, i,j, k;
	unsigned char* misBase1 = mis->misBase1;
	unsigned char* misBase2 = mis->misBase2;
	unsigned char* misPos1 = mis->misPos1;
	unsigned char* misPos2 = mis->misPos2;
	unsigned char* numMisMatch = mis->numMisMatch;
	unsigned char misMatch;
	readLength = mis->readLength;
	numSA = mis->numSA;

	for(i = 0; i < numSA; i++)
	{
		readPos = readLength*(queryId[i]);
		j = 0;
		for(k = 0, refPos=pos[offset[i]], misMatch = 0;  k < readLength; k++)
		{    
			if(ref[refPos + j] == '\n'){
				j++;
				continue;
			}
			if(!compareBase(read[readPos+k], ref[refPos+j]))
			{
				if(misMatch == 0)
				{
					misPos1[i] = k;
					misBase1[i] = read[readPos+k];
					
				}
				else if(misMatch == 1)
				{
					misPos2[i] = k;
					misBase2[i] = read[readPos+k];
				}
				misMatch++;
			}
			j++;
		}
		numMisMatch[i] = misMatch;
	}
}
